﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NamTrungBS.DataLayer;
using NamTrungBS.DataLayer.DataSetNamTrungBSTableAdapters;
using System.Configuration;

namespace NamTrungBS
{
    public partial class HoaDonShow : Form
    {
        private int maHD;

        public int MaHD
        {
            get { return maHD; }
            set { maHD = value; }
        }

        private string tenkh;

        public string Tenkh
        {
            get { return tenkh; }
            set { tenkh = value; }
        }

        public HoaDonShow()
        {
            InitializeComponent();
        }

        private void HoaDonShow_Load(object sender, EventArgs e)
        {
            DataSetNamTrungBS ds = new DataSetNamTrungBS();
            HoaDonTableAdapter hoadonAdapter = new HoaDonTableAdapter();
            ChiTietHoaDonTableAdapter chitietAdapter = new ChiTietHoaDonTableAdapter();
            NamTrungBS.DataLayer.DataSetNamTrungBS.HoaDonDataTable dtHoadon = ds.HoaDon;
            NamTrungBS.DataLayer.DataSetNamTrungBS.ChiTietHoaDonDataTable dtChitiet = ds.ChiTietHoaDon;
            hoadonAdapter.Fill(dtHoadon, maHD);
            chitietAdapter.Fill(dtChitiet, maHD);
            HoaDonRpt.Load();
            HoaDonRpt.SetDataSource(ds);
            crystalReportViewHoaDon.ReportSource = HoaDonRpt;
            string exportPath = ConfigurationSettings.AppSettings["SavePath"];
            string exportDocName = exportPath + Tenkh + "_" +
                    DateTime.Now.Day + "_" + DateTime.Now.Month + "_" + DateTime.Now.Year + "_" + DateTime.Now.Second + "s_" + DateTime.Now.Minute + "p_" + DateTime.Now.Hour + "h" + ".pdf";
            HoaDonRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, exportDocName);
            crystalReportViewHoaDon.PrintReport();
            crystalReportViewHoaDon.Show();
        }
    }
}
